package com.four.basicinfo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.four.basicinfo.entity.Information;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

import static net.sf.jsqlparser.parser.feature.Feature.select;

@Mapper
public interface InformationDao extends BaseMapper<Information> {
    /**
     * 查询基本信息
     *
     * @param id 基本信息主键
     * @return 基本信息
     */
    public Information selectInformationById(Long id);

    // 查看所有员工（合同工）
    @Select("<script>" +
            "SELECT * FROM information" +
            "<where>" +
            "    <if test=\"name != null\">" +
            " <bind name=\"Key\" value=\"'%'+name+'%'\"/>" +
            "        name like #{Key} " +
            "    </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "    <if test=\"sex != null\">" +
            "      and sex = #{sex}" +
            "   </if>" +
            "    <if test=\"employee != null\">" +
            "      and employee = #{employee}" +
            "   </if>" +
            "    <if test=\"grade != null\">" +
            "      and grade = #{grade}" +
            "   </if>" +
            "    <if test=\"duties != null\">" +
            "      and duties = #{duties}" +
            "   </if>" +
            "    <if test=\"education != null\">" +
            "      and education = #{education}" +
            "   </if>" +
            "    <if test=\"marriage != null\">" +
            "      and marriage = #{marriage}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    List<Information> canInformation(int start, int size,
                                     String name, Integer number,
                                     String sex, String employee,
                                     String grade, String duties,
                                     String education, String marriage);

    //分页
    @Select("<script>" +
            "SELECT count(*) FROM information" +
            "<where>" +
            "    <if test=\"name != null\">" +
            " <bind name=\"Key\" value=\"'%'+name+'%'\"/>" +
            "        name like #{Key} " +
            "    </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "    <if test=\"sex != null\">" +
            "      and sex = #{sex}" +
            "   </if>" +
            "    <if test=\"employee != null\">" +
            "      and employee = #{employee}" +
            "   </if>" +
            "    <if test=\"grade != null\">" +
            "      and grade = #{grade}" +
            "   </if>" +
            "    <if test=\"duties != null\">" +
            "      and duties = #{duties}" +
            "   </if>" +
            "    <if test=\"education != null\">" +
            "      and education = #{education}" +
            "   </if>" +
            "    <if test=\"marriage != null\">" +
            "      and marriage = #{marriage}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countInformation(String name, Integer number,
                                String sex, String employee,
                                String grade, String duties,
                                String education, String marriage);

    //查询个人信息
    @Select("select id, number, name, identity, sex, birth, grade, employee, compile, role," +
            " jobtitle, department, education, duties, title, birthplace, nation," +
            " party_time as partyTime, entry_date as entryDate, political_outlook as politicalOutlook, " +
            "education_type as educationType, marriage, phonenumber from information where number=#{number}")
    public Information selectByNum(String number);

    //查询合同工姓名
    @Select("select name from information where employee='合同工'")
    public List<String> selectName();

    //根据合同工姓名查工号
    @Select("select number,department from information where name=#{name}")
    public Information selectNumber(String name);

    //查询学历信息
    @Select("select id,number,fulldegree ,fulltimeprofession ,jobeducation ,jobprofession ,jobdegree " +
            "from information where number=#{number}")
    public List<Information> selectEdu(String number);

    /**
     * 修改基本信息
     *
     * @param information 基本信息
     * @return 结果
     */
    public int updateInformation(Information information);
}
